package kr.hkit.powerjava.chapter22.work2.dao;

import java.util.*;

import kr.hkit.powerjava.chapter22.work.Student;
import kr.hkit.powerjava.chapter23.*;

public class DepartmentManagerImpl implements ItemDaoInterface<Department> {
	private List<Department> arList;
	
	public DepartmentManagerImpl(ArrayList<Department> arList) {
		this.arList = arList;
	}

	@Override
	public void addItem(Department item) {
		arList.add(item);

	}

	@Override
	public void delItem(Department item) {
		arList.remove(item);

	}

	@Override
	public void updateItem(Department item) {
		if (searchItem(item)) {
			arList.set(arList.indexOf(item), item);
		} else {
			System.out.println("수정 실패");
		}
	}

	@Override
	public boolean searchItem(Department item) {
		return arList.contains(item);
	}

	@Override
	public void prnItems() {
		prnHeader();
/*		Collections.sort(arList);
*/		for(Department s : arList){
			System.out.println(s);
		}
		System.out.println();
	}

		
	private void prnHeader() {
		String str = String
				.format("%5s\t %5s\t %5s\t",
						"학과", "학과명", "층");
				System.out.println(str);
				System.out.println("====================================");
	}

	@Override
	public void prnItems(Comparator<Department> comp) {
		Collections.sort(arList, comp);
		prnItems();
	}


}
